﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_V_Login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            pllogin.Visible = true;
            plInfor.Visible = false;

            //pllogin.Visible = false;
            //plInfor.Visible = true;
        }
    }
    protected void Sublogin_ServerClick(object sender, ImageClickEventArgs e)
    {
        string loginname = txtUsername.Value.ToString();
        string loginpwd = txtPWD.Value.ToString();
        String checkCode = Request["checkCode"];
        string code = txtValidatecode.Value.ToString();
        code.ToUpper().ToString();

        if (loginname != "" && loginpwd != "")
        {
            if (checkCode == code.ToUpper().ToString())
            {
                ShowInfo(loginname, loginpwd);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('验证码错误,请重新登录！');</script>");
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('用户名和密码不能为空，登录失败！');</script>");

        }
    }

    private void ShowInfo(string UserName, string PassWord)
    {
        VPINews.BLL.UserInfo bll_user = new VPINews.BLL.UserInfo();
        VPINews.Model.UserInfo mod_user = bll_user.GetModelUser(UserName);
        if (mod_user != null && mod_user.Possword == PassWord)
        {
            Session["User"] = UserName;
            Session["PWD"] = PassWord;
            Session["userID"] = mod_user.UserID;
            this.txtUser.Value = UserName;
            pllogin.Visible = false;
            plInfor.Visible = true;
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('用户名或密码有误，登录失败！');</script>");
        }

    }

    protected void Subexit_ServerClick(object sender, ImageClickEventArgs e)
    {
        Session.Clear();
        pllogin.Visible = true;
        plInfor.Visible = false;
    }
}
